package org.lmind.example.common.web.jsp.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.lmind.example.common.web.ApplicationContext;

public class UrlTag extends TagSupport {

	private static final long serialVersionUID = -5493246579676465300L;
	
	private String value;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public int doStartTag() throws JspException {
		
		try {
			JspWriter out = pageContext.getOut();
			ApplicationContext app = (ApplicationContext)pageContext.getServletContext().getAttribute(ApplicationContext.WEB_APP_CONTEXT_NAME);
			
			String real = app.getUrlResolver().resolveUrl(value);
			out.write(real);
			return SKIP_BODY;
			
		} catch (IOException e) {
			throw new JspException(e);
		}
	}


}
